home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- #include <time.h>
-
- #ifndef O_BINARY
- #define O_BINARY 0
- #endif
-
- #ifndef __GNUC__
- unsigned long htonl(unsigned long x)
- {
- unsigned char *cp, *dp;
- unsigned long y;
- dp = &y;
- cp = &x;
- dp += 3;
- *dp-- = *cp++;
- *dp-- = *cp++;
- *dp-- = *cp++;
- *dp-- = *cp++;
- return y;
- }
-
- unsigned short htons(unsigned short x)
- {
- unsigned char *cp, *dp;
- unsigned short y;
- dp = &y;
- cp = &x;
- dp += 1;
- *dp-- = *cp++;
- *dp-- = *cp++;
- return y;
- }
- #else
- #include <unistd.h>
- #include <sys/types.h>
- #include <netinet/in.h>
- #endif
-
- int main(int argc, char *argv[])
- {
-
- int outfd;
- unsigned long cofst;
- unsigned char *bbuf, nbuf[32];
- unsigned short xshort;
- unsigned long xlong, xid;
- long bbuflen;
- int fd, maxsect;
-
- if (argc != 2) {
- fprintf(stderr, "Usage: %s inputfile\n", argv[0]);
- exit(1);
- }
-
- bbuf = malloc(8 + 4096);
-
- strcpy(bbuf, argv[1]);
- strcat(bbuf, ".pdb");
- if (!(outfd = open(bbuf, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0644)))
- exit(-1);
-
- strcpy(bbuf, "DBLK");
- bbuf[5] = 0;
- bbuf[6] = 0x10;
- bbuf[7] = 0;
-
- memset(nbuf, 0, 32);
- strncpy(nbuf, argv[1], 32);
- write(outfd, nbuf, 32);
-
- memset(nbuf, 0, 4);
- nbuf[1] = 0x88;
- nbuf[3] = 1;
- write(outfd, nbuf, 4);
-
- xlong = time(NULL) + ((66 * 365 + 17) * 24 * 3600UL);
- xlong = htonl(xlong);
- write(outfd, &xlong, 4);
- write(outfd, &xlong, 4);
- write(outfd, &xlong, 4);
-
- memset(nbuf, 0, 12);
- write(outfd, nbuf, 12);
-
- write(outfd, "DATA", 4);
- write(outfd, "BRWS", 4);
-
- nbuf[0] = 0x28;
- write(outfd, nbuf, 8);
-
- fd = open(argv[1], O_BINARY | O_RDONLY);
- xlong = lseek(fd, 0, SEEK_END);
- lseek(fd, 0, SEEK_SET);
-
- maxsect = xlong / 4096 + 1;
- xshort = htons(maxsect);
- write(outfd, &xshort, 2);
-
- cofst = 80 + 8 * maxsect;
-
- xid = 0x40000000UL + (rand() & 0x7fffffUL);
- for (;;) {
-
- bbuflen = read(fd, &bbuf[8], 4096);
-
- if (bbuflen <= 0)
- break;
-
- xlong = htonl(cofst);
- write(outfd, &xlong, 4);
- xlong = htonl(xid++);
- write(outfd, &xlong, 4);
-
- xlong = lseek(outfd, 0, SEEK_CUR);
- lseek(outfd, cofst, SEEK_SET);
- write(outfd, bbuf, bbuflen + 8);
- lseek(outfd, xlong, SEEK_SET);
- cofst += bbuflen + 8;
-
- if (bbuflen != 4096)
- break;
- }
-
- close(fd);
-
-
- xshort = 0;
- write(outfd, &xshort, 2);
-
- return 0;
- }
-